<?php

namespace App\Http\Controllers\API\Tools;

use App\Http\Controllers\Controller;
use App\Miya\Models\Info;
use Illuminate\Http\Request;

class ToolController extends Controller
{
    public function lastInfo()
    {
        $info = Info::where('status', 1)
            ->has('classify')
            ->with(['module', 'classify'])
            ->orderBy('delayed_at', 'DESC')
            ->orderBy('created_at', 'DESC')
            ->first();

        $data = $info->only(['id', 'name', 'page_views']);
        $data['image'] = asset($info->avatar);
        $data['url'] = $info->url();
        $data['time'] = $info->delayed_at ?? $info->created_at;
        $data['module'] = $info->module->name;
        $data['classify'] = $info->classify->name;

        return response()->json($data);
    }
}
